import 'package:flutter/material.dart';
import 'package:fenzi/global.dart';

class Utils {
  static showConfirmDialog({
    BuildContext context,
    String content,
    Function confirmCallback,
    Function cancelCallback,
    bool showCancelButton = false,
    bool showConfirmButton = true,
    String cancelText = "取消",
    String confirmText = "确认",
  }) {
    showDialog(
      context: context,
      builder: (context) {
        return AlertDialog(
          elevation: 0,
          contentPadding: EdgeInsets.all(0),
          content: Container(
            height: 101,
            child: Column(
              children: [
                Container(
                  padding: EdgeInsets.fromLTRB(10, 15, 10, 15),
                  decoration: BoxDecoration(),
                  child: Center(child: Text(content)),
                ),
                Container(
                  decoration: BoxDecoration(
                    border: Border(
                      top: BorderSide(
                        color: Global.fontSecondColor.withOpacity(0.3),
                        width: 1,
                      ),
                    ),
                  ),
                  child: Row(
                    children: [
                      showCancelButton
                          ? Expanded(
                              child: InkWell(
                                onTap: () {
                                  if (cancelCallback != null) cancelCallback();
                                  Navigator.of(context).pop();
                                },
                                child: Container(
                                  padding: EdgeInsets.all(13),
                                  decoration: BoxDecoration(
                                    border: Border(
                                      right: BorderSide(
                                        color: Global.fontSecondColor
                                            .withOpacity(0.3),
                                        width: 1,
                                      ),
                                    ),
                                  ),
                                  child: Center(
                                    child: Text(
                                      cancelText,
                                      style: TextStyle(
                                        fontSize: 16,
                                        color: Global.fontColor,
                                        fontWeight: FontWeight.w500,
                                      ),
                                    ),
                                  ),
                                ),
                              ),
                            )
                          : Container(),
                      showConfirmButton
                          ? Expanded(
                              child: InkWell(
                                onTap: () {
                                  if (confirmCallback != null)
                                    confirmCallback();
                                  Navigator.of(context).pop();
                                },
                                child: Container(
                                  padding: EdgeInsets.all(13),
                                  child: Center(
                                    child: Text(
                                      confirmText,
                                      style: TextStyle(
                                        fontSize: 16,
                                        color: Global.fontColor,
                                        fontWeight: FontWeight.w500,
                                      ),
                                    ),
                                  ),
                                ),
                              ),
                            )
                          : Container(),
                    ],
                  ),
                )
              ],
            ),
          ),
          shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5)),
        );
      },
    );
  }
}
